<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>lesson 30</title>
    <style>
        .area {
            width: 200px;
            height: 200px;
            background: #000;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        .mask {
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            bottom: 0;
            background: pink;
            opacity: 0.5;
        }
    </style>
    <script src="https://unpkg.com/vue@next"></script>
</head>

<body>
    <div id="root"></div>
</body>

</html>

<script>
    // Teleport 传送门
    const app = Vue.createApp({
        data() {
            return {
                show: false,
            };
        },
        methods: {
            handleClick() {
                this.show = !this.show;
            }
        },
        template: `
        <div class="area">
            <button @click="handleClick">按钮</button>
            <teleport to="body">
                <div class="mask" v-show="show"></div>    
            </teleport>
        </div>
        `
    });

    const vm = app.mount("#root");
</script>